package com.yiqi.zhiyuan.feature.certification.view;

import android.content.Intent;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.suozhang.framework.framework.BaseActivity;
import com.yiqi.zhiyuan.R;
import com.yiqi.zhiyuan.entity.vo.CarVO;

import butterknife.BindView;
import butterknife.OnClick;

public class VehicleStateActivity extends BaseActivity {

    @BindView(R.id.toolbar)
    Toolbar mToolbar;
    @BindView(R.id.iv_certificate_state)
    ImageView mIvCertificateState;
    @BindView(R.id.tv_certificate_state)
    TextView mTvCertificateState;
    @BindView(R.id.iv_certificate_state_msg)
    TextView mIvCertificateStateMsg;
    @BindView(R.id.btn_certificate_state)
    TextView mBtnCertificateState;
    private boolean isFirst = false;//是否是注册时点进来的

    private CarVO mCarVO;

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_authentication_state;
    }

    @Override
    protected void initInjector() {

    }

    @Override
    protected void initView() {
        initToolBar(mToolbar, "提交审核", true, true);
    }

    @Override
    protected void initData() {
        mCarVO = (CarVO) this.getIntent().getSerializableExtra("car_info");
        isFirst = this.getIntent().getBooleanExtra("is_first", false);
        mBtnCertificateState.setVisibility(mCarVO.getIsPass() == 1 ? View.INVISIBLE : View.VISIBLE);
        if (mCarVO.getIsPass() == 1) {
            mTvCertificateState.setText("车辆审核中");
            mIvCertificateStateMsg.setText("结果将以短信通知");
            mIvCertificateState.setImageResource(R.mipmap.ic_certificate_state_success);
        } else if (mCarVO.getIsPass() == 2) {
            mTvCertificateState.setText("认证成功");
            mIvCertificateStateMsg.setText("车辆认证已通过，快去接单吧！");
            mBtnCertificateState.setText("重新认证");
            mIvCertificateState.setImageResource(R.mipmap.ic_certificate_state_success);
        } else if (mCarVO.getIsPass() == 3) {
            mTvCertificateState.setText("车辆认证未通过");
            mIvCertificateStateMsg.setText(TextUtils.isEmpty(mCarVO.getNoPassReason()) ? "" : mCarVO.getNoPassReason());
            mBtnCertificateState.setText("去认证");
            mIvCertificateState.setImageResource(R.mipmap.ic_certificate_state_fail);
        }
    }

    //1-审核中 2通过 3失败
    @OnClick(R.id.btn_certificate_state)
    public void onViewClicked() {
        if (mCarVO.getIsPass() != 1) {
            Intent  intent = new Intent(this, AddVehicleActivity.class);
            intent.putExtra("car_info", mCarVO);
            intent.putExtra("is_first", isFirst);
            startActivity(intent);
            finish();
        }
    }
}
